<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>分类查询</title>
    <link href="./css/bootstrap.css" rel="stylesheet">
    <link href="./css/normalize.css" rel="stylesheet">
    <script src="./js/jquery.js"></script>
    <script src="./js/bootstrap.js"></script>
    <style>
        #hed{
            margin-top: 25px;
        }
    </style>
    <script>
        $(function () {
            let classification = getQueryString("classification");
            let params = {
                currentPage:1,
                size:10,
                cClassify: classification
            }
            $.get("http://localhost:8080/customer/querytype",params,function (result){
                if (result.status === 200) {
                    let page = result.data
                    if (page.data.length > 0) {
                        for (let i = 0; i < page.data.length; i++) {
                            let customer = page.data[i]
                            $("#content")
                                .append(
                                    $("<tr>")
                                        .append(
                                            //添加客户名称
                                            $("<td>")
                                                .text(customer.cName)
                                                .addClass("text-center")
                                        )
                                        // 添加所属行业
                                        .append(
                                            $("<td>")
                                                .text(customer.cIndustry)
                                                .addClass("text-center")
                                        )
                                        // 所在城市
                                        .append(
                                            $("<td>")
                                                .text(customer.cCity)
                                                .addClass("text-center")
                                        )
                                        // 联系人
                                        .append(
                                            $("<td>")
                                                .text(customer.cLinkman)
                                                .addClass("text-center")
                                        )
                                        // 操作
                                        .append(
                                            $("<td>")
                                                .append($("<button class='btn btn-info off col-lg-offset-3'>详细信息</button>").click(function () {
                                                    window.location.href = "detailedMSG.html?id=" + customer.cid
                                                }))
                                                .append($("<button class='btn btn-danger col-lg-offset-2'>删除</button>").click(function () {
                                                    let data = {
                                                        id:customer.cid
                                                    }
                                                    $.get("http://localhost:8080/customer/delete", data, function (result) {
                                                        if (result.status){
                                                            window.location.href = "listPage.html"
                                                        }
                                                    })
                                                }))
                                        )
                                        .append()
                                        .append()
                                )
                        }

                    } else {
                        $("#content")
                            .before($("<p>暂无数据</p>"))
                            .hide();
                    }
                } else {
                    $("#content")
                        .before($("<p>暂无数据</p>"))
                        .hide();
                }
            })
        })

        function getQueryString(name) {
            let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            let r = window.location.search.substr(1).match(reg);
            return r != null ? unescape(r[2]) : null
        }

        $(function (){
            $("#all").click(function (){
                window.location.href = "listPage.html"
            })
        })

        $(function (){
            $("#customer").click(function (){
                window.location.href = "addCustomer.html"
            })
        })

        $(function (){
            $("#query").click(function (){
                let querySelect = $("#select").val()
                window.location.href = "pirmaryquery.html?primaryKey="+querySelect
            })
        })
    </script>
</head>
<body>
<div id="warp" class="container-fluid">
    <div style="margin-top: 35px">
        <!--<div class="col-lg-2">
            <select id="clssify" name="cClassify">
                <option value="one">一级分类</option>
                <option value="two">二级分类</option>
                <option value="three">三级分类</option>
            </select>
        </div>-->
        <div class="col-lg-offset-1 col-lg-2">
            <button type="button" class="btn-default" id="all"><span class="glyphicon glyphicon-search">显示所有用户</span></button>
        </div>
        <div class="col-lg-3">
            <input id="select" name="query" type="text" value="请输入关键字">
            <button type="button" id="query"><span class="glyphicon glyphicon-search">查找</span></button>
        </div>
        <div class="col-lg-offset-3 col-lg-2">
            <button type="button" id="customer"><span class="glyphicon glyphicon-plus"></span>新增客户</button>
        </div>
    </div>
    <table id="content" class="table table-bordered table-condensed" style="margin-top: 90px">
        <tr>
            <th class="text-center">客户名称</th>
            <th class="text-center">所属行业</th>
            <th class="text-center">所在城市</th>
            <th class="text-center">联系人</th>
            <th class="text-center">操作</th>
        </tr>
    </table>

</div>

</body>
</html>